The
stack... The stack is a very important part of ASM programming. I
will trymy best in illustrating exactly how the stack works. The stack
isbasically a FILO buffer (First In Last Out),this
means that the first item PUSHEDinto the stack is the last one toPOPEDout. Converly the Last In, is
also the First out.
Theseare the
instructions/ideas that will be covered in this
lesson:
PUSH To add an itemto the stack we
use the PUSH instruction. You can only PUSH the
followingregisters:
AF
BC
DE
HL
IX
IY
Here are some
examples:
push af ;adds the valuestored
in AF to the stack push bc
;adds the value storedin BC to the stack
NOTE: The registerstill contains
the value it had before being PUSHED NOTE: It is very important that you DON'T
exit the program before POPPING, allPUSHED values. The operating system, I
believe, calls what is inthe stack after the last program terminates.
Having random valuesin there will cause a crash, or some unwanted
results.
POP To remove anitem from the
stack we use the POP instruction. You can only POPto the following
registers:
AF
BC
DE
HL
Here are some
examples:
pop af ;stores the valueon the
top of the ;stack in
AF (removes that value fromthe
stack) pop bc ;stores the
value on thetop of the ;stack in BC
(removes that value from the stack)